<template>
	<view>
		<view class="label" data-url="/pages/accountManage/bindWxAccount/bindWxAccount" @tap="$jumpPage">
			收款微信号
			<text v-if="!bindedWxInfo.payeeOpenId" style="color: red;">(未绑定)</text>
			<text v-else style="color: #ff9239;">(已绑定)</text>
		</view>
		<view class="input-warp u-f-ajc">
			<view>￥</view>
			<input type="digit" v-model.number="money" placeholder="最低0.3元起提" placeholder-style="font-size:30rpx;color:#BBB;" />
			<view @tap="withdrawAll">全部</view>
		</view>
		<view class="btn u-f-ajc"><button @tap="withdraw">确认提现</button></view>
		<view class="tips">
			<view>提现须知：</view>
			<view>1.每日仅可申请提现一次，提现前请先绑定收款微信号；</view>
			<view>2.默认提现到所绑定收款微信的微信钱包中。</view>
			<!-- <view>3.提现申请将在<text style="color: red;">1~3个工作日内</text>审核</view> -->
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			money: '',
			totalMoney: ''
		};
	},
	computed: {
		bindedWxInfo() {
			return this.$store.state.bindedWxInfo;
		}
	},
	onLoad() {
		this.getPromoterProfitMoney();
	},
	methods: {
		withdrawAll() {
			this.money = this.totalMoney || 0;
		},
		getPromoterProfitMoney() {
			this.$u.api._getPromoterProfitMoney().then(res => {
				this.totalMoney = res;
			});
		},
		// 提现接口
		withdraw() {
			if (!this.$u.test.amount(this.money)) {
				uni.showToast({
					icon: 'none',
					title: '请填写合法提现金额'
				});
				return;
			}
			if(!this.bindedWxInfo.payeeOpenId) {
				uni.showModal({
					title: '提示',
					content: '当前账号未绑定微信收款账户，请先确认绑定！',
					showCancel: false,
					success: () => {
							uni.navigateTo({
								url:'/pages/accountManage/bindWxAccount/bindWxAccount'
							})
					}
				}); 
				return 
			}
			if (this.money > this.totalMoney) {
				uni.showToast({
					icon: 'none',
					title: '可提现余额不足'
				});
				return;
			}
			if (Number(this.money) < 0.3) {
				uni.showModal({
					title: '提示',
					content: '您的输入提现金额不足0.3元！请注意查看提现规则。',
					showCancel: false
				});
				return;
			}
			
			if (this.lock) {
				return;
			}
			this.lock = true;
			this.$u.api
				._promoterWithdraw({ money: this.money })
				.then(res => {
					uni.showModal({
						title: '提示',
						content: '提现申请提交成功！',
						showCancel: false,
						success: res => {
							uni.$emit('withDraw');
							uni.navigateBack();
						}
					});
				})
				.finally(() => {
					this.lock = false;
				});
		}
	}
};
</script>

<style lang="scss">
.label {
	margin-left: 60rpx;
	margin-top: 30rpx;
	color: #808080;
}
.input-warp {
	margin-top: 100rpx;
	justify-content: center;

	> view:nth-child(1) {
		font-size: 60rpx;
		font-weight: bold;
	}
	> input:nth-child(2) {
		font-size: 50rpx;
		text-align: center;
		width: 220rpx;
		margin: 0 20rpx;
		border-bottom: 2rpx solid #eee;
		height: 100%;
		margin-bottom: -10rpx;
	}
	> view:nth-child(3) {
		width: 90rpx;
		font-size: 24rpx;
		color: #ff9239;
		height: 46rpx;
		line-height: 44rpx;
		text-align: center;
		border: 2rpx solid #ff9239;
		border-radius: 10rpx;
		margin-left: 10rpx;
		box-sizing: content-box;
	}
}

.btn {
	> button {
		width: 580rpx;
		background-color: #ff9239;
		color: #ffffff;
		border-radius: 45rpx;
		margin: 100rpx 0;
	}
}
.tips {
	padding: 0 60rpx;
	color: #999999;
	font-size: 26rpx;
	line-height: 2;

	> view:nth-child(1) {
		color: #333333;
		font-weight: 600;
		padding-bottom: 10rpx;
	}
}
</style>
